package 时间复杂度.基础;

public class binarySearch {
    int fun1(int[] array, int x) {
        int begin = 0;
        int end = array.length - 1;
        int mid = 0;
        while (begin < end) {
            mid = (begin + end) / 2;
            if (x == array[mid]) {
                return mid;
            }
            if (array[mid] < x) {
                begin = mid + 1;
            }
            if (array[mid] > x) {
                end = mid - 1;
            }
        }
        return -1;
    }
    //时间复杂度:log2^n
}


